package fr.vvins.core.user.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import fr.vvins.core.user.entity.UserLog;

@Repository
public interface UserLogRepository extends CrudRepository<UserLog, Integer> {

	@Query("from UserLog where product.id=?1")
	List<UserLog> findByProductId(Integer id);

	@Query("from UserLog where vigneron.id=?1")
	List<UserLog> findByVigneronId(Integer id);

	@Query("from UserLog where action.id in ?1 and product.id=?2")
	List<UserLog> findByActionIdAndProductId(List<Integer> actionId, Integer id);

	@Query("from UserLog where action.id in ?1 and vigneron.id=?2")
	List<UserLog> findByActionIdAndVigneronId(List<Integer> actionId, Integer id);

	@Query("from UserLog where (action.id in ?1 and product.content.key=?2)")
	List<UserLog> findByActionIdAndProductKey(List<Integer> actionId, String key);

	@Query("from UserLog where action.id in ?1 and vigneron.content.key=?2")
	List<UserLog> findByActionIdAndVigneronKey(List<Integer> actionId, String key);

	@Query("from UserLog where action.id in ?1 and user.id=?2")
	List<UserLog> findByActionIdAndUserId(List<Integer> actionId, Integer userId);
	
	@Query("from UserLog where product.content.id=?1")
	List<UserLog> findByProductContentId(Integer contentId);

	@Query("from UserLog where vigneron.content.id=?1")
	List<UserLog> findByVigneronContentId(Integer contentId);

	@Query("from UserLog where product.content.key=?1")
	List<UserLog> findByProductContentKey(String key);

	@Query("from UserLog where vigneron.content.key=?1")
	List<UserLog> findByVigneronContentKey(String key);

	@Query("from UserLog where user.id=?1")
	List<UserLog> findByUserId(Integer userId);

}
